home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / asm_n_z.zip / RUN.ASM < prev    next >
Assembly Source File  |  1986-03-01  |  7KB  |  313 lines

  1. cseg    segment para public 'code'
  2. org    100h
  3.  
  4. ; This program is used to load an EXE file faster than DOS.
  5. ; To use it, enter 'RUN prog', where prog is a valid EXE program.
  6. ; The file may be any size, but for programs less than 64K,
  7. ; making a COM file using EXETOCOM.BIN as a header works faster.
  8.  
  9. recct    equ 504         ; max recs per read
  10.  
  11. run    proc far
  12.     assume cs:cseg,ds:cseg,ss:nothing,es:nothing
  13.  
  14.     mov sp,offset estak    ; point to internal stack
  15.     call p100        ; initialize
  16.     call p200        ; open file
  17.     jmp p300        ; copy this prog to hi memory
  18. p010:    call p400        ; read exe file to lo memory
  19.     jmp p600        ; relocate and execute prog
  20.  
  21. p050:    mov ah,9        ; print error message
  22.     int 21h
  23.     mov ax,oseg
  24.     push ax
  25.     xor ax,ax
  26.     push ax
  27.     ret 0            ; terminate
  28.  
  29. p100    proc near        ; initialize
  30.     mov dx,offset copyr
  31.     mov ah,9        ; print copyright message
  32.     int 21h
  33.  
  34.     mov ax,ds
  35.     mov oseg,ax        ; save original seg
  36.     add ax,10h
  37.     mov nseg,ax        ; save new prog seg
  38.     mov si,2
  39.     mov bx,[si]        ; get top of memory from psp
  40.     mov topmem,bx
  41.  
  42.     mov ax,offset endprog
  43.     add ax,15
  44.     and ax,0fff0h
  45.     mov eprog,ax        ; point to end of prog
  46.     mov cl,4
  47.     shr ax,cl
  48.     mov bx,ds
  49.     add ax,bx
  50.     mov dtads,ax        ; point to start dta
  51.  
  52.     mov si,5ch        ; point to 1st fcb
  53.     mov di,offset fcb    ; & work fcb
  54.     mov cx,37
  55.     rep movsb        ; copy it
  56.  
  57.     mov di,offset fcb+9    ; make sure extension is 'EXE'
  58.     mov si,offset exe
  59.     mov cx,3
  60.     repnz movsb        ; copy 'EXE' to extension
  61.  
  62.                 ; juggle fcbs in psp
  63.     mov si,81h        ; point to command line in psp
  64.     mov di,5ch        ; point to first fcb in psp
  65.     mov ax,2901h
  66.     int 21h         ; parse first file name (prog to execute)
  67.  
  68.                 ; rearrange command line
  69.     mov di,81h        ; point to start of command line
  70.     mov bx,80h
  71.     mov ch,0
  72.     mov cl,[bx]        ; get length of command line
  73.     add cx,di
  74.     sub cx,si        ; new command line length
  75.     mov [bx],cl        ; save it
  76.     inc cl            ; copy carriage return too!
  77.     repnz movsb        ; move command line down
  78.  
  79.     mov si,offset fcbfill    ; fill fcbs with blanks
  80.     mov di,offset 5ch
  81.     mov cx,16
  82.     rep movsb        ; clear first fcb
  83.     mov si,offset fcbfill
  84.     mov di,offset 6ch
  85.     mov cx,16
  86.     rep movsb        ; clear second fcb
  87.     mov si,81h        ; get command line back
  88.     mov di,5ch        ; point to first fcb
  89.     mov ax,2901h
  90.     mov bx,offset drives
  91.     int 21h         ; parse first parm
  92.     cmp al,1        ; error?
  93.     jbe p110        ; no
  94.     mov [bx],al        ; set error in lo byte
  95.  
  96. p110:    mov di,6ch
  97.     mov ax,2901h
  98.     int 21h         ; parse second parm
  99.     cmp al,1        ; error?
  100.     jbe p120        ; no
  101.     mov [bx+1],al        ; set error in hi byte
  102.  
  103. p120:    ret
  104. p100    endp
  105.  
  106. p200    proc near        ; open file
  107.     mov dx,offset fcb
  108.     mov ah,0fh
  109.     int 21h
  110.     and al,0ffh        ; error?
  111.     jz p210         ; no
  112.     mov dx,offset errmsg1
  113.     jmp p050
  114.  
  115. p210:    mov si,offset fcb+16    ; get file size
  116.     mov ax,[si]        ; lower part
  117.     mov cl,7
  118.     shr ax,cl        ; divide by 128
  119.     mov bx,ax        ; hold in bx
  120.     mov ax,[si+2]        ; upper part of file size
  121.     mov cl,9
  122.     sal ax,cl        ; divide by 128
  123.     add ax,bx        ; total file size divided by 128
  124.     mov norecs,ax        ; save as norecs
  125.  
  126.     mov ax,128
  127.     mov si,offset fcb+14    ; set recsize = 128
  128.     mov [si],ax
  129.     mov al,0        ; zero 5 bytes in fcb
  130.     mov di,offset fcb+32
  131.     mov cx,5
  132.     repnz stosb        ; clear fcb bytes 32 - 36
  133.  
  134.     mov ax,norecs
  135.     mov cl,3
  136.     sal ax,cl        ; # of pghs for prog
  137.     add ax,dtads        ; top of prog (pghs)
  138.     mov bx,topmem        ; top of memory
  139.     cmp bx,ax        ; is there room?
  140.     jae p220        ; yes
  141.     mov dx,offset errmsg4
  142.     jmp p050
  143.  
  144. p220:    ret
  145. p200    endp
  146.  
  147. p300:                ; read exe header
  148.     mov cx,4
  149.     call p500        ; read 4 recs
  150.     mov si,eprog
  151.     mov ax,[si]        ; get EXE signature
  152.     cmp ax,5a4dh        ; valid exe file?
  153.     jz p310         ; yes
  154.     mov dx,offset errmsg2
  155.     jmp p050
  156.  
  157. p310:                ; check stack placement
  158.     mov ax,[si+10h]     ; get value for sp
  159.     mov cl,4
  160.     shr ax,cl        ; convert to pghs
  161.     add ax,nseg        ; add base seg
  162.     add ax,[si+0eh]     ; and sp offset
  163.     mov bx,topmem        ; get top of memory
  164.     cmp bx,ax        ; is there room for the stack?
  165.     jae p315        ; yes
  166.     mov dx,offset errmsg4
  167.     jmp p050
  168.  
  169. p315:    mov ax,[si+8]        ; get header size (pghs)
  170.     mov cl,3
  171.     shr ax,cl        ; divide by 8 to get 128-byte recs
  172.     sub ax,4        ; already read
  173.     mov cx,ax
  174.     jcxz p320        ; no more header
  175.     call p500        ; read rest of header
  176.  
  177. p320:    mov ax,norecs        ; recs left
  178.     mov cl,3
  179.     sal ax,cl        ; convert to pghs
  180.     add ax,nseg        ; plus start point gives copy destination
  181.     mov bx,dtads        ; end of header
  182.     cmp ax,bx        ; is start point above header?
  183.     jae p325        ; yes
  184.     mov ax,bx        ; no - change copy destination
  185.  
  186. p325:    mov es,ax        ; copy prog here
  187.     sub bx,oseg        ; minus psp gives pghs to copy
  188.     mov cl,3
  189.     sal bx,cl        ; words to copy
  190.     mov cx,bx
  191.     xor di,di
  192.     xor si,si
  193.     rep movsw        ; copy it
  194.  
  195.     mov di,offset p330
  196.     push es
  197.     push di
  198.     ret 0            ; jump to new copy
  199.  
  200. p330:    push es
  201.     pop ds            ; set ds=es=new cs
  202.     mov ax,es
  203.     mov ss,ax        ; set ss=es
  204.     jmp p010
  205.  
  206. p400    proc near        ; read file
  207.     mov ax,nseg
  208.     mov dtads,ax
  209. p410:    mov cx,norecs        ; # of recs left
  210.     sub cx,recct        ; 63K worth?
  211.     ja p420         ; yes
  212.     add cx,recct        ; no - read remainder
  213.     jmp p430
  214.  
  215. p420:    mov cx,recct        ; read 63K
  216. p430:    call p500        ; read file
  217.  
  218. p440:    mov cx,norecs        ; any more to read?
  219.     jcxz p450        ; no
  220.     jmp p410        ; read next block
  221.  
  222. p450:    ret
  223. p400    endp
  224.  
  225. p500    proc near        ; read file - cx contains recs to read
  226.     push ds
  227.     mov bx,dtads
  228.     mov ds,bx        ; new ds
  229.     mov dx,0
  230.     mov ah,1ah
  231.     int 21h         ; set dta
  232.     pop ds
  233.     mov dx,offset fcb
  234.     mov ah,27h
  235.     int 21h         ; random block read
  236.     and al,0ffh        ; error?
  237.     jz p510         ; no
  238.     mov dx,offset errmsg3
  239.     jmp p050
  240.  
  241. p510:    mov ax,cx        ; adjust dta for next read
  242.     sub norecs,ax
  243.     mov cl,3
  244.     sal ax,cl        ; 8 pghs/rec
  245.     add dtads,ax
  246.     ret
  247. p500 endp
  248.  
  249. p600:    mov ax,nseg        ; relocate and execute it
  250.     mov si,eprog
  251.     mov bx,si
  252.     add bx,[si+18h]     ; first relocation item
  253.     mov cx,[si+6]        ; # of items
  254.     jcxz p620        ; none
  255. p610:    mov dx,[bx+2]        ; get code seg
  256.     add dx,ax        ; add start seg
  257.     mov es,dx        ; in es
  258.     mov di,[bx]        ; set instruction in es
  259.     add es:[di],ax        ; add start seg
  260.     add bx,4        ; do another
  261.     loop p610        ; done?
  262.  
  263. p620:                ; pass control to exe prog
  264.     mov ax,nseg        ; new prog seg
  265.     add ax,[si+0eh]     ; plus ss offset gives new ss
  266.     cli
  267.     mov ss,ax
  268.     mov sp,[si+10h]
  269.     sti
  270.  
  271.     mov ax,nseg        ; new prog seg
  272.     add ax,[si+16h]     ; plus cs offset gives new cs
  273.     mov bx,[si+14h]     ; new ip
  274.     push ax
  275.     push bx
  276.     mov bx,drives        ; get drive status
  277.  
  278.     mov ax,oseg        ; set up ds & es
  279.     mov ds,ax
  280.     mov es,ax
  281.  
  282.     mov ah,1ah        ; reset dta
  283.     mov dx,80h
  284.     int 21h
  285.     mov ax,bx        ; drive status in ax
  286.  
  287.     ret 0            ; far return to exe prog
  288.  
  289. copyr    db 'RUN - Copyright 1983 Data Base Decisions',10,13,'$'
  290. errmsg1 db 'Program not found',7,10,13,'$'
  291. errmsg2 db 'Header not found ',7,10,13,'$'
  292. errmsg3 db 'Unable to load program',7,10,13,'$'
  293. errmsg4 db 'Not enough memory',7,10,13,'$'
  294.  
  295. oseg    dw 0            ; original data seg
  296. nseg    dw 0            ; start of new prog
  297. topmem    dw 0            ; top of memory
  298. norecs    dw 0            ; # of 128 byte recs in file
  299. dtads    dw 0            ; dta data seg
  300. drives    dw 0            ; drive status for fcbs
  301. exe    db 'EXE'                ; file extension
  302. fcb    db 37 dup(0)        ; work fcb
  303. eprog    dw 0            ; end of this prog
  304. stak    db 16 dup('stack   ')   ; temp stack
  305. estak    db 0
  306. fcbfill db 0,11 dup(' '),4 dup(0)       ; fcb filler
  307.  
  308. endprog equ this word
  309.  
  310. run    endp
  311. cseg    ends
  312. end    run
  313.